(function(){
	angular.module('app').component('chartLine',{
		templateUrl: 'app/components/chart.line.component/chart.line.component.html',
		controller: chartLineComponet,
		controllerAs: 'vm',
		bindings:{
			configline: '<',
			catName: '<' 
		}

	});

	chartLineComponet.$inject = ['$scope','chartLineService','$rootScope'];

	function chartLineComponet($scope,chartLineService,$rootScope){
		console.log('chartLine component js loading');
		var vm = this;
		vm.chart = {
			title: '',
			root_catName:''
		}
		
		// console.log(vm.configline);

		vm.getHTTP = getHTTP; //数据初始化
		
		$scope.$watch('vm.catName',function(newValue,oldValue){
			// console.log('chartLineComponet: change'+newValue);
			titleFormat();
			vm.getHTTP();
		});


		//标题格式化
        function titleFormat() {
            if (vm.catName == '/') {
                vm.chart.title = "全网类目销售额走势图";
            } else if (vm.catName.indexOf('--') == -1) {
                vm.chart.title = vm.catName + "类目销售额走势图";
            } else {
                vm.chart.title = vm.catName.split('--')[vm.catName.split('--').length - 1] + "类目销售额走势图";
            }
        }

        function getHTTP(){
        	chartLineService.get(vm.catName,vm.configline).then(function(){
        		
        		$rootScope.$emit('echart_draw_line_EV',vm.configline,'industry_line');
        	});
        }
	}
})();